#!/usr/bin/env node

const http = require('http'),
      log = console.log,
      qs = require('querystring')

http.createServer((req, res) => {
  log(`${req.method} ${req.url} HTTP/${req.httpVersion}`)

  log(req.headers)

  log()

  if (req.method !== 'POST') {
    res.end('ok')
    return
  }

  let data = ''
  req.on('data', (chunk) => {
    data += chunk
  })
  req.on('end', () => {
    console.log(qs.parse(data))
    res.end('ok')
  })
  //req.pipe(process.stdout);
  res.end('ok')
}).listen(3000)
